/*============================================================================*/
/*                   CONTINENTAL AUTOMOTIVE SYSTEMS                           */
/*============================================================================*/
/*                        OBJECT SPECIFICATION                                */
/*============================================================================*
* name:            APPWinLif.c
* version:         1.1
* created_by:      Lizette Acosta/Rodrigo Casados
* date_created:    June 22 2013
*=============================================================================*/
/* DESCRIPTION : APP file for Window Lifter.                                  */
/*============================================================================*/
/* FUNCTION COMMENT :                                                         */
/*                                                                            */
/*============================================================================*/
/*                               OBJECT HISTORY                               */
/*============================================================================*/
/*  REVISION |   DATE      |                               |      AUTHOR      */
/*----------------------------------------------------------------------------*/
/*  1.1      | 22/June/2013 |                              | Lizette Acosta   */
/*                                                           Rodrigo Casados  */
/*============================================================================*/

#include "APPWinLif.h"



void Winlif(void)
{
static uint16_t Btn;
static uint16_t BtnP;
	
	
	if (AppFlag==PINCH)
	{
		Btn=PINCH;
	}
	else
	{
		Btn=Debouncer_Checkbtn();	
	}
	
	if (AppFlag2>FALSE)
	{
		Btn=0;
	}

	BtnP=Debouncer_AntiPinch();
	
	if (BtnP==PINCH)
	{
		if (Btn==BTN1 || Btn==BTN2)
		{
			AppFlag=PINCH;
			Btn=PINCH;
		}
	}
			
			switch(Btn)
			{
				case FALSE:
				{
					SM_BTN(BTN0_STATE);	
					break;
				}
				case BTN1:
				{
					SM_BTN(BTN1_STATE);	
					break;
				}
				
				case BTN2:
				{
					SM_BTN(BTN2_STATE);	
					break;
				}
				
				case BTN3:
				{
					SM_BTN(BTN3_STATE);
					break;
				}
				
				case BTN4:
				{
					SM_BTN(BTN4_STATE);
					break;
				}
				case PINCH:
				{
					SM_BTN(BTN5_STATE);
					break;
				}
				default:
					break;
			}
	  	
}


void SM_BTN(E_SM_BTN e_sm_btn)
{
	switch(e_sm_btn)
	{
		case BTN0_STATE:
		{
			vfnPorts_LedOFF();	
			break;
		}
		case BTN1_STATE:
		{
			vfnPorts_LedUP();
			LedCtril_NormalUP();
			break;
		}
		case BTN2_STATE:
		{
			vfnPorts_LedUP();
			LedCtrl_AUP();
			break;
		}
		case BTN3_STATE:
		{
			vfnPorts_LedDOWN();
			LedCtril_NormalDOWN();
			break;
		}
		case BTN4_STATE:
		{
			vfnPorts_LedDOWN();
			LedCtrl_ADOWN();
			break;
		}
		case BTN5_STATE:
		{
			vfnPorts_LedDOWN();
			LedCtrl_PINCHDOWN();
			vfnPorts_LedOFF();	
			Delay_5s();
			break;
		}
		default:
			break;
	}
}